package cglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author:zimmor
 * @Date: 2021/3/25 13:08
 * @Description cglib代理工具类
 * @version: 1.0.0
 */

public class CglibDynamicProxy {
    public static Object createProxy(Class clazz){
       return Enhancer.create(clazz, new MethodInterceptor() {
            public Object intercept(Object target, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
                System.out.println("代理生效");
                return methodProxy.invokeSuper(target, args);
            }
        });
    }
}
